<template>
	<view class="search_box">
		<u-search :placeholder="placeText" :bgColor="bg?bg:'#fff'" :inputStyle="{
			height:'70rpx'
		}" :searchIconSize="40" @input="debouncedOnInput" v-model="keyword" :showAction="false"></u-search>
	</view>
</template>

<script>
	export default {
		name: "search",
		props: ['placeText', 'bg'],
		data() {
			return {
				keyword: ''
			};
		},
		methods: {
			debounce(func, wait) {
				let timeout;
				return (...args) => {
					clearTimeout(timeout);
					timeout = setTimeout(() => func.apply(this, args), wait);
				};
			},
			onInput(value) {
				// console.log('value: ', value);
				this.$emit('input', value); // 将当前的关键词传递给父组件
			}
		},
		created: function() {
			this.debouncedOnInput = this.debounce(this.onInput, 500)
		}
	}
</script>

<style lang="scss" scoped>
	.search_box {
		margin: 15rpx;
	}
</style>